<template>
  <basic-container>
    <div class="container-body">
      <el-form :inline="true" :model="query" class="demo-form-inline">
        <el-form-item label="年度">
          <el-input size="small" v-model="query.year" placeholder="year" clearable></el-input>
        </el-form-item>
        <el-form-item label="学号">
          <el-input size="small" v-model="query.xh" placeholder="xh" clearable></el-input>
        </el-form-item>
        <el-form-item label="姓名">
          <el-input size="small" v-model="query.xm" placeholder="xm" clearable></el-input>
        </el-form-item>
        <el-form-item label="年级">
          <el-input size="small" v-model="query.nj" placeholder="nj" clearable></el-input>
        </el-form-item>
        <el-form-item label="学院名称">
          <el-input size="small" v-model="query.xymc" placeholder="xymc" clearable></el-input>
        </el-form-item>
        <el-form-item label="系名称">
          <el-input size="small" v-model="query.xmc" placeholder="xmc" clearable></el-input>
        </el-form-item>
        <el-form-item label="专业名称">
          <el-input size="small" v-model="query.zymc" placeholder="zymc" clearable></el-input>
        </el-form-item>
        <el-form-item label="班级名称">
          <el-input size="small" v-model="query.bjmc" placeholder="bjmc" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="onSearch" :loading="loading">搜索
          </el-button>
          <el-button size="small" icon="el-icon-delete" @click="searchReset" :loading="loading">清空</el-button>
        </el-form-item>
      </el-form>
      <div class="btn-operate">
<!--        <el-button v-if="permissions.adis_adreport07_add" @click="showAddView" type="primary" size="small" icon="el-icon-plus">-->
<!--          新增-->
<!--        </el-button>-->
        <el-button v-if="permissions.sys_user_import_export" class="filter-item" plain type="primary" size="small" icon="el-icon-upload" @click="$refs.excelUpload.show()">
          导入
        </el-button>
      </div>
      <el-table header-row-class-name="container-table-header"
                :data="data" size="small"
                style="width: 100%;margin-bottom: 20px;"
                row-key="id"
                border stripe
                v-loading="loading">
        <el-table-column prop="year" label="年度">
        </el-table-column>
        <el-table-column prop="xh" label="学号">
        </el-table-column>
        <el-table-column prop="xm" label="姓名">
        </el-table-column>
        <el-table-column prop="xz" label="学制">
        </el-table-column>
        <el-table-column prop="nj" label="年级">
        </el-table-column>
        <el-table-column prop="xymc" label="学院名称">
        </el-table-column>
        <el-table-column prop="xmc" label="系名称">
        </el-table-column>
        <el-table-column prop="zymc" label="专业名称">
        </el-table-column>
        <el-table-column prop="bjmc" label="班级名称">
        </el-table-column>
        <el-table-column prop="byrq" label="毕业日期">
        </el-table-column>
        <el-table-column prop="byjl" label="毕业结论">
        </el-table-column>
        <el-table-column
          label="操作" width="170">
          <template slot-scope="scope">
            <el-button v-if="permissions.adis_adreport07_get" type="text" size="small" icon="el-icon-view" @click="showViewBox(scope.row)">查看</el-button>
<!--            <el-button v-if="permissions.adis_adreport07_add" type="text" size="small" icon="el-icon-edit" @click="showEditBox(scope.row)">编辑</el-button>-->
<!--            <el-button v-if="permissions.adis_adreport07_del" type="text" size="small" icon="el-icon-delete"@click="handleDelete(scope.row)">删除</el-button>-->
          </template>
        </el-table-column>
      </el-table>
      <div class="container-page">
        <el-pagination
          @size-change="sizeChange"
          @current-change="currentChange"
          :current-page="page.current"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </div>
    </div>

    <el-dialog :title="formTitle" :visible.sync="formBox" :close-on-click-modal="!formBox"
               :append-to-body="true" :before-close="resetForm" width="1200px" top="5vh">
      <el-form ref="optForm" :model="form" label-width="130px">
        <el-form-item label="主键id" prop="id" :rules="{required: true, message: '主键id不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.id" placeholder="主键id"></el-input>
        </el-form-item>
        <el-form-item label="学校标识码" prop="xxbsm" :rules="{required: true, message: '学校标识码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xxbsm" placeholder="学校标识码"></el-input>
        </el-form-item>
        <el-form-item label="学校名称" prop="xxmc" :rules="{required: true, message: '学校名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xxmc" placeholder="学校名称"></el-input>
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyshxydm" :rules="{required: true, message: '统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.tyshxydm" placeholder="统一社会信用代码"></el-input>
        </el-form-item>
        <el-form-item label="年度" prop="year" :rules="{required: true, message: '年度不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.year" placeholder="年度"></el-input>
        </el-form-item>
        <el-form-item label="学号" prop="xh" :rules="{required: true, message: '学号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xh" placeholder="学号"></el-input>
        </el-form-item>
        <el-form-item label="姓名" prop="xm" :rules="{required: true, message: '姓名不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xm" placeholder="姓名"></el-input>
        </el-form-item>
        <el-form-item label="身份证号码" prop="sfzhm" :rules="{required: true, message: '身份证号码不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.sfzhm" placeholder="身份证号码"></el-input>
        </el-form-item>
        <el-form-item label="学制" prop="xz" :rules="{required: true, message: '学制不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xz" placeholder="学制"></el-input>
        </el-form-item>
        <el-form-item label="年级" prop="nj" :rules="{required: true, message: '年级不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.nj" placeholder="年级"></el-input>
        </el-form-item>
        <el-form-item label="学院名称" prop="xymc" :rules="{required: true, message: '学院名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xymc" placeholder="学院名称"></el-input>
        </el-form-item>
        <el-form-item label="系名称" prop="xmc" :rules="{required: true, message: '系名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xmc" placeholder="系名称"></el-input>
        </el-form-item>
        <el-form-item label="专业名称" prop="zymc" :rules="{required: true, message: '专业名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.zymc" placeholder="专业名称"></el-input>
        </el-form-item>
        <el-form-item label="班级名称" prop="bjmc" :rules="{required: true, message: '班级名称不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.bjmc" placeholder="班级名称"></el-input>
        </el-form-item>
        <el-form-item label="毕业日期" prop="byrq" :rules="{required: true, message: '毕业日期不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.byrq" placeholder="毕业日期"></el-input>
        </el-form-item>
        <el-form-item label="毕业结论" prop="byjl" :rules="{required: true, message: '毕业结论不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.byjl" placeholder="毕业结论"></el-input>
        </el-form-item>
        <el-form-item label="毕业证书号" prop="byzsh" :rules="{required: true, message: '毕业证书号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.byzsh" placeholder="毕业证书号"></el-input>
        </el-form-item>
        <el-form-item label="学位类型" prop="xwlx" :rules="{required: true, message: '学位类型不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xwlx" placeholder="学位类型"></el-input>
        </el-form-item>
        <el-form-item label="学位证书号" prop="xwzsh" :rules="{required: true, message: '学位证书号不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.xwzsh" placeholder="学位证书号"></el-input>
        </el-form-item>
        <el-form-item label="毕业设计题目" prop="bysjtm" :rules="{required: true, message: '毕业设计题目不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.bysjtm" placeholder="毕业设计题目"></el-input>
        </el-form-item>
        <el-form-item label="毕业设计指导教师" prop="bysjzdjs" :rules="{required: true, message: '毕业设计指导教师不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.bysjzdjs" placeholder="毕业设计指导教师"></el-input>
        </el-form-item>
        <el-form-item label="毕业审查意见" prop="byscyj" :rules="{required: true, message: '毕业审查意见不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.byscyj" placeholder="毕业审查意见"></el-input>
        </el-form-item>
        <el-form-item label="毕业综合成绩" prop="byzhcj" :rules="{required: true, message: '毕业综合成绩不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.byzhcj" placeholder="毕业综合成绩"></el-input>
        </el-form-item>
        <el-form-item label="实习单位" prop="sxdw" :rules="{required: true, message: '实习单位不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.sxdw" placeholder="实习单位"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="bz" :rules="{required: true, message: '备注不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.bz" placeholder="备注"></el-input>
        </el-form-item>
        <el-form-item label="创建日期" prop="createtime" :rules="{required: true, message: '创建日期不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.createtime" placeholder="创建日期"></el-input>
        </el-form-item>
        <el-form-item label="修改日期" prop="modifytime" :rules="{required: true, message: '修改日期不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.modifytime" placeholder="修改日期"></el-input>
        </el-form-item>
        <el-form-item label="操作状态" prop="czzt" :rules="{required: true, message: '操作状态不能为空', trigger: ['blur', 'change']}">
          <el-input v-model="form.czzt" placeholder="操作状态"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm" size="small" icon="el-icon-close">关闭</el-button>
         <el-button v-if="!isView" type="primary" @click="submit" size="small" icon="el-icon-check">保存</el-button>
      </span>
    </el-dialog>

    <el-dialog :title="formTitle" :visible.sync="viewBox" :close-on-click-modal="!viewBox"
               :append-to-body="true" :before-close="resetForm" width="1200px" top="5vh">
      <el-form ref="optForm" :model="form" label-width="130px">
        <el-form-item label="主键id" prop="id" :rules="{required: true, message: '主键id不能为空', trigger: ['blur', 'change']}">
          {{form.id}}
        </el-form-item>
        <el-form-item label="学校标识码" prop="xxbsm" :rules="{required: true, message: '学校标识码不能为空', trigger: ['blur', 'change']}">
          {{form.xxbsm}}
        </el-form-item>
        <el-form-item label="学校名称" prop="xxmc" :rules="{required: true, message: '学校名称不能为空', trigger: ['blur', 'change']}">
          {{form.xxmc}}
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyshxydm" :rules="{required: true, message: '统一社会信用代码不能为空', trigger: ['blur', 'change']}">
          {{form.tyshxydm}}
        </el-form-item>
        <el-form-item label="年度" prop="year" :rules="{required: true, message: '年度不能为空', trigger: ['blur', 'change']}">
          {{form.year}}
        </el-form-item>
        <el-form-item label="学号" prop="xh" :rules="{required: true, message: '学号不能为空', trigger: ['blur', 'change']}">
          {{form.xh}}
        </el-form-item>
        <el-form-item label="姓名" prop="xm" :rules="{required: true, message: '姓名不能为空', trigger: ['blur', 'change']}">
          {{form.xm}}
        </el-form-item>
        <el-form-item label="身份证号码" prop="sfzhm" :rules="{required: true, message: '身份证号码不能为空', trigger: ['blur', 'change']}">
          {{form.sfzhm}}
        </el-form-item>
        <el-form-item label="学制" prop="xz" :rules="{required: true, message: '学制不能为空', trigger: ['blur', 'change']}">
          {{form.xz}}
        </el-form-item>
        <el-form-item label="年级" prop="nj" :rules="{required: true, message: '年级不能为空', trigger: ['blur', 'change']}">
          {{form.nj}}
        </el-form-item>
        <el-form-item label="学院名称" prop="xymc" :rules="{required: true, message: '学院名称不能为空', trigger: ['blur', 'change']}">
          {{form.xymc}}
        </el-form-item>
        <el-form-item label="系名称" prop="xmc" :rules="{required: true, message: '系名称不能为空', trigger: ['blur', 'change']}">
          {{form.xmc}}
        </el-form-item>
        <el-form-item label="专业名称" prop="zymc" :rules="{required: true, message: '专业名称不能为空', trigger: ['blur', 'change']}">
          {{form.zymc}}
        </el-form-item>
        <el-form-item label="班级名称" prop="bjmc" :rules="{required: true, message: '班级名称不能为空', trigger: ['blur', 'change']}">
          {{form.bjmc}}
        </el-form-item>
        <el-form-item label="毕业日期" prop="byrq" :rules="{required: true, message: '毕业日期不能为空', trigger: ['blur', 'change']}">
          {{form.byrq}}
        </el-form-item>
        <el-form-item label="毕业结论" prop="byjl" :rules="{required: true, message: '毕业结论不能为空', trigger: ['blur', 'change']}">
          {{form.byjl}}
        </el-form-item>
        <el-form-item label="毕业证书号" prop="byzsh" :rules="{required: true, message: '毕业证书号不能为空', trigger: ['blur', 'change']}">
          {{form.byzsh}}
        </el-form-item>
        <el-form-item label="学位类型" prop="xwlx" :rules="{required: true, message: '学位类型不能为空', trigger: ['blur', 'change']}">
          {{form.xwlx}}
        </el-form-item>
        <el-form-item label="学位证书号" prop="xwzsh" :rules="{required: true, message: '学位证书号不能为空', trigger: ['blur', 'change']}">
          {{form.xwzsh}}
        </el-form-item>
        <el-form-item label="毕业设计题目" prop="bysjtm" :rules="{required: true, message: '毕业设计题目不能为空', trigger: ['blur', 'change']}">
          {{form.bysjtm}}
        </el-form-item>
        <el-form-item label="毕业设计指导教师" prop="bysjzdjs" :rules="{required: true, message: '毕业设计指导教师不能为空', trigger: ['blur', 'change']}">
          {{form.bysjzdjs}}
        </el-form-item>
        <el-form-item label="毕业审查意见" prop="byscyj" :rules="{required: true, message: '毕业审查意见不能为空', trigger: ['blur', 'change']}">
          {{form.byscyj}}
        </el-form-item>
        <el-form-item label="毕业综合成绩" prop="byzhcj" :rules="{required: true, message: '毕业综合成绩不能为空', trigger: ['blur', 'change']}">
          {{form.byzhcj}}
        </el-form-item>
        <el-form-item label="实习单位" prop="sxdw" :rules="{required: true, message: '实习单位不能为空', trigger: ['blur', 'change']}">
          {{form.sxdw}}
        </el-form-item>
        <el-form-item label="备注" prop="bz" :rules="{required: true, message: '备注不能为空', trigger: ['blur', 'change']}">
          {{form.bz}}
        </el-form-item>
        <el-form-item label="创建日期" prop="createtime" :rules="{required: true, message: '创建日期不能为空', trigger: ['blur', 'change']}">
          {{form.createtime}}
        </el-form-item>
        <el-form-item label="修改日期" prop="modifytime" :rules="{required: true, message: '修改日期不能为空', trigger: ['blur', 'change']}">
          {{form.modifytime}}
        </el-form-item>
        <el-form-item label="操作状态" prop="czzt" :rules="{required: true, message: '操作状态不能为空', trigger: ['blur', 'change']}">
          {{form.czzt}}
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
          <el-button @click="resetForm" size="small" icon="el-icon-close">关闭</el-button>
      </span>
    </el-dialog>

    <!--excel 模板导入 -->
    <excel-upload
      ref="excelUpload"
      title="用户信息导入"
      url="/exam/adReport07/import"
      temp-name="用户信息.xlsx"
      temp-url="/admin/sys-file/local/user.xlsx"
    ></excel-upload>
  </basic-container>
</template>

<script>
import {delObj, fetchList, getObj, submit} from "@/api/data/jwxt/bysxxb";
import {mapGetters} from "vuex";
import ExcelUpload from "@/components/upload/excel.vue";

export default {
  components: {
    ExcelUpload
  },
  dictTypes: [],
  data() {
    return {
      importBox: false,
      isEdit: false,
      isView: false,
      viewBox: false,
      formBox: false,
      formTitle: '',
      loading: false,
      query: {},
      form: {},
      page: {
        size: 10,
        current: 1,
        total: 0
      },
      data: [],
      Authorization: 'Bearer ' + this.$store.getters.access_token,
    }
  },
  computed: {
    ...mapGetters(["permissions"])
  },
  created() {
    this.onLoad(this.page);
  },
  methods: {
    submit() {
      this.$refs['optForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.fileList && this.fileList.map((file) => {
            this.form.cover = file.response ? file.response.data.url : file.url
          });
          this.fileListVideo && this.fileListVideo.map((file) => {
            this.form.videoUrl = file.response ? file.response.data.url : file.url
          });
          submit(this.form).then(() => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.resetForm();
            this.onLoad(this.page);
          }, () => {
            this.loading = false;
          });
        } else {
          return false;
        }
      });
    },
    showAddView() {
      this.formTitle = '新增';
      this.formBox = true;
    },
    showEditBox(row) {
      getObj(row.id).then((res) => {
        this.form = res.data.data;
        this.formTitle = '编辑';
        this.formBox = true;
        this.isEdit = true;
        // this.fileList = [];
        // if (res.data.data.cover) {
        //   this.fileList.push({url: res.data.data.cover});
        // }
        //
        // this.fileListVideo = [];
        // this.fileListVideo.push({url: res.data.data.videoUrl});
      });
    },
    showViewBox(row) {
      getObj(row.id).then((res) => {
        this.form = res.data.data;
        this.formTitle = "查看";
        this.viewBox = true;
        // this.fileList = [];
        // if (res.data.data.cover) {
        //   this.fileList.push({url: res.data.data.cover});
        // }
        //
        // this.fileListVideo = [];
        // this.fileListVideo.push({url: res.data.data.videoUrl});
      });
    },
    handleDelete(row) {
      this.$confirm("确定将选择的数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        return delObj(row.id);
      })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    resetForm() {
      this.formBox = false;
      this.isEdit = false;
      this.isView = false;
      this.form = {
        houseType: 1, // 景点
        tags: []
      };
      this.formTitle = '';
      this.$refs['optForm'] && this.$refs['optForm'].resetFields();
      this.viewBox = false;
      this.fileList = [];
      this.fileListVideo = [];
      this.auditBox = false;

      this.customerBox = false;
      this.customerList = [];

      this.commentBox = false;
      this.commentList = [];
    },
    onSearch() {
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.current = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(current) {
      this.page.current = current;
      this.onLoad(this.page);
    },
    sizeChange(size) {
      this.page.size = size;
      this.onLoad(this.page);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      fetchList(Object.assign(params, this.query, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
      }, () => {
        this.loading = false;
      });
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      this.showUploadButton = true
    },
    handleSuccess(response, file, fileList) {
      this.fileList = fileList;
      if (this.fileList.length >= 1) {
        this.showUploadButton = false
      }
    },
    handlePreview(file) {
      window.open(file.url ? file.url : file.response.data.url)
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
  }
};
</script>

<style>
</style>
